package com.itheima.d6_jdk8_time;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

public class Test1_LocalDate {
    public static void main(String[] args) {
        // 0、获取本地日期对象(不可变对象)
        LocalDate nowDate = LocalDate.now();
        System.out.println("nowDate = " + nowDate);
        LocalTime nowTime = LocalTime.now();
        System.out.println("nowTime = " + nowTime);
        LocalDateTime nowDateTime = LocalDateTime.now();
        System.out.println("nowDateTime = " + nowDateTime);

        LocalDate date = LocalDate.of(2033, 12, 12);
        System.out.println("date = " + date);



        // 1、获取日期对象中的信息(年，月，日，星期获取)
        int year = nowDate.getYear();
        System.out.println("year = " + year);
        DayOfWeek dayOfWeek = nowDate.getDayOfWeek();
        System.out.println("dayOfWeek = " + dayOfWeek);

        // 2、直接修改某个信息: withYear、withMonth、withDayOfMonth、withDayOfYear
        //新的日期API数据值是不变的，如果对日期信息改变，会得到新的日期对象对象。
        LocalDate newDate = nowDate.withYear(2034);
        System.out.println("nowDate = " + nowDate);//2023-02-26
        System.out.println("newDate = " + newDate);//2034-02-26

        // 3、把某个信息加多少: plusYears、plusMonths、plusDays、plusWeeks
        LocalDate tenYears = nowDate.plusYears(10);
        System.out.println("tenYears = " + tenYears);
        LocalDate date2 = nowDate.plusDays(10000);
        System.out.println("date2 = " + date2);

        // 4、把某个信息减多少：minusYears、minusMonths、minusDays、minusWeeks
        LocalDate minusYears = nowDate.minusYears(10);//十年之前
        System.out.println("minusYears = " + minusYears);//2013-02-26

        // 5、获取指定日期的LocalDate对象： public static LocalDate of(int year, int month, int dayOfMonth)
        LocalDate date3 = LocalDate.of(3033, 3, 3);
        System.out.println("date3 = " + date3);

        // 6、判断2个日期对象，是否相等，在前还是在后： equals isBefore isAfter
        LocalDate d1 = LocalDate.of(2023, 1, 1);
        LocalDate d2 = LocalDate.of(2023, 1, 1);
        LocalDate d3 = LocalDate.of(2023, 1, 10);

        System.out.println("d1.equals(d2) = " + d1.equals(d2));
        System.out.println("d2.isBefore(d3) = " + d2.isBefore(d3));//true  判断d2是否在d3前
        System.out.println("d2.isAfter(d3) = " + d2.isAfter(d3));//false   判断d2是否在d3后

    }
}
